<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>南京大学职业咨询室预约平台</title>
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='assets/i/ico_128X128.ico') }}">
    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <link rel="icon" sizes="192x192" href="{{ url_for('static', filename='assets/i/app-icon72x72@2x.png') }}">
    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="apple-touch-icon-precomposed" href="{{ url_for('static', filename='assets/i/app-icon72x72@2x.png') }}">
    <!-- Tile icon for Win8 (144x144 + tile color) -->
    <meta name="msapplication-TileImage" content="{{ url_for('static', filename='assets/i/app-icon72x72@2x.png') }}">
    <meta name="msapplication-TileColor" content="#0e90d2">

    <link rel="stylesheet" href="{{ url_for('static', filename='assets/css/amazeui.min.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='assets/css/amazeui.datetimepicker.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='assets/css/app.css', v='1.4') }}">
    <script src="{{ url_for('static', filename='assets/js/jquery.min.js') }}"></script>
    <script src="{{ url_for('static', filename='assets/js/amazeui.min.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='assets/js/amazeui.datetimepicker.min.js') }}"></script>

</head>

<body>
<div class="admin-header">
    <!--<div class="header-back" onclick="history.back()">返回</div>-->
    <div class="header-title">设置咨询师</div>
</div>
<div class="content">
    <div class="alert alert-warning">
        {% with messages = get_flashed_messages() %}
          {% if messages %}
            <ul class=flashes>
            {% for message in messages %}
            <div class="am-alert am-alert-secondary" data-am-alert>
              <button type="button" class="am-close">&times;</button>
              <div style="text-align: center;">{{ message }}</div>
            </div>
            {% endfor %}
            </ul>
          {% endif %}
        {% endwith %}
    </div>
    <div class="book-item-warp">
        <div class="book-item-title">
            <div class="fl"> <strong>编号：</strong>{{li['id']}}</div>
        </div>
        <div class="book-item-line">
            <div class="fl"> <strong>教师姓名：</strong>{{ li['name'] }}</div>
        </div>
        <div class="book-item-line">
            <div class="fl"> <strong>手机号：</strong>{{li['contact']}}</div>
        </div>
        
        <div class="book-item-line">
            <div class="fr"> 操作：<button value="{{li['id']}}" onClick="delete_teacher(this.value)" class="am-btn-danger">删除</button></div>
        </div>
        <div class="book-item-line">
            <div class="fl"> <strong>简介：</strong>{{li['intro']}}</div>
        </div>
        <div class="book-item-line">
         <textarea rows="5" class="input" type="text" name="fds" id="id_intro" style="width:100%;border:1px solid #e6e6e6;" placeholder="在此填入简介信息，填写完毕提交简介" value=""></textarea>
        </div>
        
        <div class="book-item-line" style="padding:5px">
        <div class="fr">
             <button value="{{li['id']}}" onClick="teacher_add_intro(this.value)" class="am-btn am-btn-primary am-btn-sm">提交简介</button></div>
        </div>
        <div class="book-item-line">
            <div class="fl"><strong>个人图片：</strong></div>
        </div>
        <div class="book-item-line" style="padding-top:5px;padding-bottom:5px;">
            <form name="njusub" enctype="multipart/form-data">
                {{ form.csrf_token }}  
                <div class="fl" style="float: left;width:110px;">
                    <img height="100" width="100" src="{{ li['image']|safe }}"  alt="" />
                </div>
                <div style="zoom:1;overflow:hidden;">
                    <div class="" style="float: none;width:100px;text-align: center;">
                        <div class="am-form-group am-form-file" style="height:100%; line-height: 100%;margin:5px 0">
                          <button type="button" class="am-btn am-btn-default" style="vertical-align: middle;font-size:14px;">
                            <i class="am-icon-cloud-upload"></i> 选择图片</button>
                          <input type="file"  name="file" id="myfiles">
                        </div>
                    </div>
                    <div class="" style="float: none;height:20px;line-height:20px;">
                        <input style="width: 100%;font-size:12px;text-align:left;padding:0px;" type="text" class="am-btn" id="filename" value=""></div>
                    <div class="" style="width:25%;text-align: left;">
                        <input type="submit" class="am-btn am-btn-primary" cont="{{li['contact']}}" tcid="{{li['id']}}" value="上传图片" onClick="uploadimg(this)">
                    </div>
                </div>

            </form>
        </div>
        <div class="book-item-line">&nbsp;
        </div>
        <div class="book-item-line">
            <div class="am-cf"><button onClick="add_teacher_pb()" class="am-btn am-btn-primary am-btn-sm"><i class="am-icon-plus"></i>增加排班</button></div>
        </div>
        <div id="set_pb" style="display:none;">
            <div><strong>&nbsp;&nbsp;星期：</strong>
                <select class="sec_notes" id="weekpb" data-am-selected="{btnWidth: '80%', btnHeight: '100%', btnSize: 'sm'}">
                    <option value="1">周一</option>
                    <option value="2">周二</option>
                    <option value="3">周三</option>
                    <option value="4">周四</option>
                    <option value="5">周五</option>
                </select>
            </div>
            <div><strong>&nbsp;&nbsp;时间：</strong>
                <select class="sec_notes" id="timepb" data-am-selected="{btnWidth: '80%', btnHeight: '100%', btnSize: 'sm'}">
                    
                </select>
            </div>
            <div class="book-item-line">
            </div>
            <div class="book-item-line">
                <div class="fr">
                    <button value="{{li['id']}}" onClick="commit_teacher_pb(this.value)" class="am-btn am-btn-primary am-btn-sm">提交排班</button>
                </div>
            </div>
        </div>
        <div class="book-item-line am-cf">&nbsp;
            <div class="am-form-group">
                <button type="text" value="{{li['id']}}" id="id_disable_booking" name="disable" value="" class="am-btn am-btn-warning" onclick="disable_booking(this.value)">设置不可预约</button>
                <button type="text" value="{{li['id']}}" id="id_enable_booking" name="enable" value="" class="am-btn am-btn-success" onclick="enable_booking(this.value)">取消不可预约</button>
                <p>{{disabled_interval}}</p>
                <input type="text" style="margin: 10px auto;width:100%;" value="" placeholder="输入不可预约的起始日期" id="datetimepicker_begin" class="am-form-field">
                <input type="text" style="margin: 10px auto;width:100%;" value="" placeholder="输入不可预约的终止日期" id="datetimepicker_end" class="am-form-field">
            </div>
        </div>
    </div>
        
    <div class="book-item-line">
    </div>
</div>

<div class="am-cf">
    <button type="text" id="back_" value="返回" onclick="javascript:window.location.href='./admin_get_teacher_lists';" class="am-btn am-btn-default">返&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;回</button>
</div>

<script type="text/javascript">
    var date = new Date();
    $("#datetimepicker_begin").datetimepicker({
        format: 'yyyy-mm-dd',
        minView: 'month',
        autoclose:true,
        startDate: date
    });

    $("#datetimepicker_end").datetimepicker({
        format: 'yyyy-mm-dd',
        minView: 'month',
        autoclose:true,
        startDate: date
    });
    
    function commit_teacher_pb(val)
    {
        if ($("#weekpb").val() == undefined || $("#weekpb").val() == "") {
            alert("请选择星期排班");
            return false;
        };
        
        if ($("#timepb").val() == undefined || $("#timepb").val() == "") {
            alert("请选择时间排班");
            return false;
        };
        
        var csrftoken = $('meta[name=csrf-token]').attr('content');$.ajaxSetup({beforeSend: function(xhr, settings) {if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {xhr.setRequestHeader("X-CSRFToken", csrftoken)} }});
        $.ajax({type: 'post',url: '/add_tch_pb',data: {tcid:val,wkpb:$("#weekpb").val(),tmpb:$("#timepb").val()},async: 0,success: function(data) {
                alert("添加咨询师排班成功！");
            },error: function() {alert('服务端异常');}});
    }
    
    function add_teacher_pb()
    {
        var label1 = document.getElementById('set_pb');
        
        var csrftoken = $('meta[name=csrf-token]').attr('content');$.ajaxSetup({beforeSend: function(xhr, settings) {if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {xhr.setRequestHeader("X-CSRFToken", csrftoken)} }});
        $.ajax({type: 'post',url: '/existed_time',data: {a: null},async: 0,success: function(data) {
                var jsondata = eval(data);
                document.getElementById("timepb").options.length=0;
                $.each(jsondata, function(idx, item) {
                    document.getElementById("timepb").options.add(new Option(item.stm,item.stm));
                });
            },error: function() {alert('服务端异常');}});
        
        label1.style.display='block';
    }
    function delete_teacher(val)
    {
        conf = window.confirm("确定删除该咨询师用户？删除咨询时将同时删除其所有排班，已被预约的咨询排班信息将被自动取消！");
        if (conf) {
            var csrftoken = $('meta[name=csrf-token]').attr('content');
            $.ajaxSetup({
                beforeSend: function(xhr, settings) {
                    if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                        xhr.setRequestHeader("X-CSRFToken", csrftoken)
                    }
                }
            });
            $.ajax({
                // 请求发送方式
                type: 'post',
                // 验证文件
                url: '/delete_teacher',
                // 用户输入的帐号密码
                data: {
                    'tcid': val
                },
                // 异步，不写默认为True
                async: 0,
                //请求成功后的回调
                success: function(data) {
                    alert(data.msg);
                    //window.location.reload();
                    window.location.href = './admin_get_teacher_lists'
                },
                error: function() {
                    alert('服务端异常');
                }
            });
        };
    }

    function teacher_add_intro(val)
    {
        if ($("#id_intro").val() == "") {
            alert("请先填写简介！");
            return false;
        };
        conf = window.confirm("确定为咨询师添加简介？");
        if (conf) {
            var csrftoken = $('meta[name=csrf-token]').attr('content');
            $.ajaxSetup({
                beforeSend: function(xhr, settings) {
                    if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                        xhr.setRequestHeader("X-CSRFToken", csrftoken)
                    }
                }
            });
            $.ajax({
                // 请求发送方式
                type: 'post',
                // 验证文件
                url: '/add_tch_intro',
                // 用户输入的帐号密码
                data: {
                    'tcid': val,
                    'intro': $("#id_intro").val()
                },
                // 异步，不写默认为True
                async: 0,
                //请求成功后的回调
                success: function(data) {
                    if(data.status == false)
                    {
                        alert("设置咨询师简介失败");
                    }
                    window.location.reload();
                    //window.location.href = './admin_get_teacher_lists'
                },
                error: function() {
                    alert('服务端异常');
                }
            });
        };
    }

    // 修改教师排班
    function modif_tch_time(val) {
        conf = window.confirm("确定修改咨询师排班？");
        if (conf) {
            var csrftoken = $('meta[name=csrf-token]').attr('content');$.ajaxSetup({beforeSend: function(xhr, settings) {if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {xhr.setRequestHeader("X-CSRFToken", csrftoken)} }});
            $.ajax({type: 'post',url: '/modify_tch_pb',data: {'contact':val,'wkd':$("#tch_date_selc_"+val).val(),'stm': $("#tch_time_selc_"+val).val()},async: 0,success: function(data) {
                },error: function() {alert('服务端异常');}});
        }
    }
    
    function enable_booking(val)
    {
        conf = window.confirm("该操作将取消不可预约状态！确认操作？");
        if (conf) {            
            var csrftoken = $('meta[name=csrf-token]').attr('content');$.ajaxSetup({beforeSend: function(xhr, settings) {if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {xhr.setRequestHeader("X-CSRFToken", csrftoken)} }});
            $.ajax({type: 'post',url: '/add_tch_booking',data: {'tcid':val},async: 0,success: function(data) {
            alert(data.msg);
            window.location.reload();
                },error: function() {alert('服务端异常');}});
        }
    }

    function disable_booking(val)
    {
        if ($("#datetimepicker_begin").val()=="")
        {
            alert("请选择不可预约的起始日期");
            return false;
        }

        if ($("#datetimepicker_end").val()=="")
        {
            alert("请选择不可预约的终止日期");
            return false;
        }
        
        conf = window.confirm("确认设置不可预约的时间段？");
        if (conf) {           
            var csrftoken = $('meta[name=csrf-token]').attr('content');$.ajaxSetup({beforeSend: function(xhr, settings) {if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {xhr.setRequestHeader("X-CSRFToken", csrftoken)} }});
            $.ajax({type: 'post',url: '/add_tch_unbooking',data: {'tcid':val,'begindate':$("#datetimepicker_begin").val(),'enddate': $("#datetimepicker_end").val()},async: 0,success: function(data) {
            alert(data.msg);
            window.location.reload();
                },error: function() {alert('服务端异常');}});
        }
    }

    var pullfiles=function(){ 
        // love the query selector
        var fileInput = document.querySelector("#myfiles");
        var files = fileInput.files;
        // cache files.length 
        var fl=files.length;
        var i=0;

        while ( i < fl) {
            // localize file var in the loop
            var file = files[i];
            //alert(file.name);
            document.getElementById("filename").value = '已选文件：'+file.name;
            i++;
        }    
    }

    function uploadimg(obj)
    {
        document.njusub.action="/upload_tch_image?tcid="+$(obj).attr("tcid")+"&cont="+$(obj).attr("cont");
        document.njusub.method="post";
        document.njusub.submit();
    }

    // set the input element onchange to call pullfiles
    document.querySelector("#myfiles").onchange=pullfiles;
</script>
</body>

</html>
